import axios from 'axios'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
const request = axios.create({
  baseURL: '/wapi',
  timeout: 3000,
})
request.interceptors.request.use((config) => {
  NProgress.start()
  return config
})
request.interceptors.response.use(
  (res) => {
    NProgress.done()
    if (res.data.code === 0) {
      return res.data
    } else {
      //alert(res.data.message)
      return Promise.reject(res.data.message)
    }
  },
  (err) => {
    NProgress.done()
    alert(err)
    return Promise.reject(err)
  }
)

export default request
